var app = angular.module("newApp", []),
	parid=UI.getParameterByName('parId'),
	groupId=UI.getParameterByName('groupId'),
	rptType=UI.getParameterByName('rptType'),
	rptCycleId=UI.getParameterByName('rptCycleId'),
	modelId=UI.getParameterByName('modelId');
var timeout_json=function(data,$window){ 
	if (data.returnCode == 999994) {
		var ss = 3;
		layer.msg(data.returnMessage + "！<strong class='Ajax_Out'>" + ss + "</strong> 秒后前往登录页", 50, -1);
		var picInt = setInterval(function() {
			if (ss >= 1) {
				ss = ss - 1;
				$('.Ajax_Out').text(ss);
			} else {
				clearInterval(picInt);
				try{
					$window.parent.location.href = data.returnData;
					$window.location.href = data.returnData;
				}catch(e){ 
					log('timeout!')
				}
			}
		}, 1000);
		return false;
	}
}

app.config(function($httpProvider) {
    $httpProvider.defaults.headers.put['Content-Type'] = 'application/x-www-form-urlencoded';
    $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
    $httpProvider.defaults.headers.post['Content-Type'] = 'application/json';
	$httpProvider.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
 
    // Override $http service's default transformRequest
    $httpProvider.defaults.transformRequest = [function(data) {
        /**
         * The workhorse; converts an object to x-www-form-urlencoded serialization.
         * @param {Object} obj
         * @return {String}
         */
        var param = function(obj) {
            var query = '';
            var name, value, fullSubName, subName, subValue, innerObj, i;
            for (name in obj) {
                value = obj[name];
                if (value instanceof Array) {
                    for (i = 0; i < value.length; ++i) {
                        subValue = value[i];
                        fullSubName = name + '[' + i + ']';
                        innerObj = {};
                        innerObj[fullSubName] = subValue;
                        query += param(innerObj) + '&';
                    }
                } else if (value instanceof Object) {
                    for (subName in value) {
                        subValue = value[subName];
                        fullSubName = name + '[' + subName + ']';
                        innerObj = {};
                        innerObj[fullSubName] = subValue;
                        query += param(innerObj) + '&';
                    }
                } else if (value !== undefined && value !== null) {
                    query += encodeURIComponent(name) + '='
                            + encodeURIComponent(value) + '&';
                }
            }
            return query.length ? query.substr(0, query.length - 1) : query;
        };
        return angular.isObject(data) && String(data) !== '[object File]'
                ? param(data)
                : data;
    }];
});
var $tmpButton;
app.controller('newCtrl', function($scope, $http, $window, $timeout) {
	$scope.rptConfig =false;
	if(modelId==null){
		$scope.rptConfig = true;
	}
	$scope.flag = false;
	$scope.flagS = true;
	$scope.ifmIds = [],
	$scope.ifmNames = [],
	$scope.ifmIsSensitivity = [];
	if(modelId!=null){
		var url = basePath + 'rpt/view/selectByid.do?modelId='+modelId;
	}else{
		var url = basePath + 'rpt/view/select.do';
	}
	$http.post(url).success(function(data) {
		if(modelId!=null){
			content = $scope.content = data.returnData;
			var moudleLen = content.length,
				moudleArr = [],
				planNameArr = [],
				planIdArr = [],
				planSensitiveArr =[];
			for(var i=0;i<moudleLen;i++){
				planNameArr[i] = [],planIdArr[i] = [],planSensitiveArr[i] = [];
				moudleArr.push(content[i].moduleName);
				var planLen = content[i].planItems.length;
				for(var j=0;j<planLen;j++){
					planNameArr[i].push(content[i].planItems[j].planName);
					planIdArr[i].push(content[i].planItems[j].planId);
					planSensitiveArr[i].push(content[i].planItems[j].planSensitive);
				}
				$scope.ifmNames[i] = planNameArr[i].join(',');
				$scope.ifmIds[i] = planIdArr[i].join(',');
				$scope.ifmIsSensitivity[i] = planSensitiveArr[i].join(',');
			}
		}else{
			content = $scope.content = data.returnData[rptType];
			var moudleLen = content.modulelist.length,
				moudleArr = [];
			for(var i=0;i<moudleLen;i++){
				moudleArr.push(content.modulelist[i].name);
			}
		}
		
		$.each(moudleArr, function(index,value) {//moudleArr["新闻舆情概述","一周数据总览","一周数据总览表"]
			//模块的显示
			var moudleElement = $("#moudleId").clone();
			$(".mtable").append(moudleElement);
			var id = moudleElement.attr('id');
			moudleElement.attr('id',id+index);
			moudleElement.attr('class','moudleClass');
			var curId = moudleElement.attr('id');
			$("#"+curId).attr("ng-show",$scope.flagS);
			$("#"+curId).removeClass("ng-hide");
			//统计方案的显示
			$scope.edit.qNameList($scope.ifmIds[index],$scope.ifmNames[index],$scope.ifmIsSensitivity[index]);
			//模块的名称
			var name = moudleElement.children().eq(0).attr('id');
			moudleElement.children().eq(0).attr('id',name+index);
			var curName = moudleElement.children().eq(0).attr('id')
			$("#"+curName).text(value);
			//筛选按钮的区分
			moudleElement.children().eq(2).children().eq(0).attr("class","green editExaDataBtn"+index);
			var editExaDataLayer = null;
			moudleElement.find('.editExaDataBtn'+index).live('click',function(){
				$("#hidValue").val(index);
				editExaDataLayer = $.layer({
					type: 1,
					title: false,
					offset:['0px',''],//控制坐标的位置
					area: ['900', 'auto'],
					border: [0], //去掉默认边框
					shade: [0.3, '#000'], //去掉遮罩
					closeBtn: [0, false], //去掉默认关闭按钮
					fadeIn: 500,
					move: "#editExaData_tile",
					page: {
						dom: '#editExaDataLayer'
					}
				});
				$tmpButton=$(this);
//				console.log($tmpButton.attr("class"));
				var strId = $(this).attr('ifm_id');
				var ifmIdArr = strId.split(",");
				subPage=0;
				numList=10;
				$scope.edit.qTagList($(this), ifmIdArr, "", curPage, numList, 0);
				
				//自设关闭
				$('#editExaDataLayer > .closeBtn').live('click', function() {
					$scope.ifmIds[$("#hidValue").val()] = moudleElement.find('.editExaDataBtn'+index).attr("ifm_id");
					$scope.ifmNames[$("#hidValue").val()] = moudleElement.find('.editExaDataBtn'+index).attr("ifm_name");
					$scope.ifmIsSensitivity[$("#hidValue").val()] = moudleElement.find('.editExaDataBtn'+index).attr("ifm_sensitive");
					curPage=1;
					layer.close(editExaDataLayer);
					$(".enterKeyDownElement").val('');
				});
			});
		});
	});
	
	//浮层确定
	$('#editExaDataLayer .confirm').live('click', function() {
		$scope.edit.qNameList($scope.ifmIds[$("#hidValue").val()],$scope.ifmNames[$("#hidValue").val()],$scope.ifmIsSensitivity[$("#hidValue").val()]);
		curPage=1;
		layer.closeAll();
		$(".enterKeyDownElement").val('');
	});
	
	$scope.edit = {
		"qNameList": function(ids, names, sensitive) {
			var dataIndex = $("#hidValue").val();
	        var $selectShowSpan = $(".editExaDataBtn"+dataIndex);
	        var $showSpan = $selectShowSpan.parent().prev().children();
	        $selectShowSpan.attr({
	            ifm_id: ids,
	            ifm_name: names,
	            ifm_sensitive: sensitive
	        });
	        $showSpan.attr({
	            ifm_id: ids,
	            title: names,
	            ifm_sensitive: sensitive
	        });
	        $showSpan.text(names);
	    },
		"qTagList": function(_this, ifmIdArr, jsons, pIndex, pageSize, flagTag) {
			//单页显示总条数为‘全部’时，默认为1000
			if(isNaN(pageSize)){
				pageSize=1000;
			}
			var _obj = $("#CustomsAreaList");
			$.ajax({
				type: "POST",
				url: basePath + "group/selectGroupScheme.do?pageIndex="+pIndex+"&pageSize="+pageSize+"&gId="+groupId,
//				url: basePath + "rpt/view/selectByid.do?modelId=" + modelId,
				data: jsons,
				success: function(data) {
					if(data.returnCode == 10000) {
						var s2 = data.returnData.length;
						var strHead = "<div class='selects w60'>复选框</div><div class='ifmNames w150'>方案名称</div><div class='ifmNotes w536'>方案备注</div>";
						var strPage = "<div class='pages' style='position:relative;'><div class='ui_page' id='pageArea'></div></div>";
						if(s2 > 0) {
							var htmls = "";
							for(var i = 0; i < s2; i++) {
								var checkedBtn = "";
								var checked = "";
								var ifm_id2 = data.returnData[i].ifmId;
								var num = ifmIdArr.length;
								var dataIndex = $("#hidValue").val();
								if(flagTag==0){
									for(var nn = 0; nn < num; nn++) {
										if(getSs2(ifm_id2,dataIndex)||getSs2(ifm_id2,dataIndex)==0) {
											checkedBtn = "true";
											checked = "checked";
											break;
										} else {
											checkedBtn = "false";
											checked = "";
										}
									}
								}else if(flagTag==1){
									for(var nn = 0; nn < num; nn++) {
										if(getSs(ifm_id2)||getSs(ifm_id2)==0) {
											checkedBtn = "true";
											checked = "checked";
											break;
										} else {
											checkedBtn = "false";
											checked = "";
										}
									}
								}
								htmls += '<tr class="td infoLlist"><td class="tc w60"><span class="ui_checkbox '  + checked + '" ifm_id= ' + data.returnData[i].ifmId + ' ifm_name= ' + data.returnData[i].ifmName + ' ifm_sensitivity= ' + data.returnData[i].ifmIsSensitivity + ' checkedBtn=' + checkedBtn + '></span></td><td class="tc w150 tName"><font>' + data.returnData[i].ifmName + '</font></td><td class="tc w536"><font title="'+ data.returnData[i].ifmNote +'">' + data.returnData[i].ifmNote + '</font></td>';
							}
							$(".headDiv").html(strHead);
							_obj.html(htmls);
							$(".pageDiv").html(strPage);
							//加入分页
							paging.loadPage(data);
							//判断是否全选
							checkTrueFalse();
						}else if(s2 < 1) {
							$(".headDiv").html(strHead);
							_obj.html("<tr><td class='tc h36' colspan='3'>很遗憾，暂无信息方案！</td></tr>");
						}
					} else if(data.returnCode == 999994) {
						setUserTimeout(data);
					} else {
						layer.msg(data.returnMessage, 2, -1);
					}
				},
				error: function(message) {
					layer.msg("操作失败，请重试！", 2, -1);
				},
				beforeSend: function() {
					var imgGif = "<p class='loadingGif'></p>";
					_obj.html(imgGif);
				}
			});
		}
	}
	
	var getSs=function(v){
		if($scope.ifmIds[$("#hidValue").val()]&&$scope.ifmIds[$("#hidValue").val()]!=""){
			var cls=$scope.ifmIds[$("#hidValue").val()].split(',');
			for(var i=0;i<cls.length;i++){
				if(v==cls[i]){
					return false || i;
				}
			}
		}
	}
	
	var getSs2=function(v,index){
		var ids = $(".editExaDataBtn"+index).attr("ifm_id");
		if(ids&&ids!=""){
			var cls = ids.split(',');
			for(var ii=0;ii<cls.length;ii++){
				if(v==cls[ii]){
					return false || ii;
				}
			}
		}
	}
	
	$(".infoLlist .ui_checkbox").live("click", function() {
		if($(this).attr("checkedBtn") == "true") {
			$(this).attr("checkedBtn", "false");
			$(this).removeClass("checked");
			if($(this).attr("ifm_id")!=undefined){
				var qc=getSs($(this).attr("ifm_id"));
				if(qc||qc==0){
					var ifmIdsArr=$scope.ifmIds[$("#hidValue").val()].split(',');
					var ifmNamesArr=$scope.ifmNames[$("#hidValue").val()].split(',');
					var ifmIsSensitivityArr=$scope.ifmIsSensitivity[$("#hidValue").val()].split(',');
					ifmIdsArr.splice(qc,1);
					ifmNamesArr.splice(qc,1);
					ifmIsSensitivityArr.splice(qc,1);
					$scope.ifmIds[$("#hidValue").val()]=ifmIdsArr.join(',');
					$scope.ifmNames[$("#hidValue").val()]=ifmNamesArr.join(',');
					$scope.ifmIsSensitivity[$("#hidValue").val()]=ifmIsSensitivityArr.join(',');
				}
			}
		} else {
			$(this).attr("checkedBtn", "true");
			$(this).addClass("checked");
			if($(this).attr("ifm_id")!=undefined){
				var qc=getSs($(this).attr("ifm_id"));
				if(!qc){
					if($scope.ifmIds[$("#hidValue").val()] == null || $scope.ifmIds[$("#hidValue").val()] == ""){
						$scope.ifmIds[$("#hidValue").val()] = "";
						$scope.ifmNames[$("#hidValue").val()] = "";
						$scope.ifmIsSensitivity[$("#hidValue").val()] = "";
					}
					if($scope.ifmIds[$("#hidValue").val()]!=""){
						$scope.ifmIds[$("#hidValue").val()]+=(','+$(this).attr("ifm_id"));
						$scope.ifmNames[$("#hidValue").val()]+=(','+$(this).attr("ifm_name"));
						$scope.ifmIsSensitivity[$("#hidValue").val()]+=(','+$(this).attr("ifm_sensitivity"));
					}else{
						$scope.ifmIds[$("#hidValue").val()]+=$(this).attr("ifm_id");
						$scope.ifmNames[$("#hidValue").val()]+=$(this).attr("ifm_name");
						$scope.ifmIsSensitivity[$("#hidValue").val()]+=$(this).attr("ifm_sensitivity");
					}
				}
			}
		}
	});

	$(".selectAllAreaGoGo .allSel").live("click", function() {
		var checkedbtn = $(this).attr("checkedbtn");
		var len = $("#CustomsAreaList .infoLlist .ui_checkbox").length;
		//判断在点击全选按钮之前，列表中是否存在已勾选的状态
		for(var ii=0;ii<len;ii++){
			if($("#CustomsAreaList .infoLlist .ui_checkbox").eq(ii).attr("checkedbtn")=="true"){
				$("#CustomsAreaList .infoLlist .ui_checkbox").eq(ii).attr("data-select","true");
			}else{
				$("#CustomsAreaList .infoLlist .ui_checkbox").eq(ii).removeAttr("data-select");
			}
		}
		if(checkedbtn == "false") {
			$("#CustomsAreaList .infoLlist .ui_checkbox, .allSel").addClass("checked").attr("checkedbtn", "true");
			for(var i=0;i<len;i++){
				if($("#CustomsAreaList .infoLlist .ui_checkbox").eq(i).attr("data-select")=="true"){
					var	nn = "",names = "",sensitive = "";
				}else{
					var nn = $("#CustomsAreaList .infoLlist .ui_checkbox").eq(i).attr("ifm_id"),
						names = $("#CustomsAreaList .infoLlist .ui_checkbox").eq(i).attr("ifm_name"),
						sensitive = $("#CustomsAreaList .infoLlist .ui_checkbox").eq(i).attr("ifm_sensitivity");
				}
				var qc=getSs(nn);
				if(!qc){
					if($scope.ifmIds[$("#hidValue").val()] == null || $scope.ifmIds[$("#hidValue").val()] == ""){
						$scope.ifmIds[$("#hidValue").val()] = "";
						$scope.ifmNames[$("#hidValue").val()] = "";
						$scope.ifmIsSensitivity[$("#hidValue").val()] = "";
					}
					if($scope.ifmIds[$("#hidValue").val()]!=""){
						$scope.ifmIds[$("#hidValue").val()]+=(nn!="" ? (',' + nn) : nn),
						$scope.ifmNames[$("#hidValue").val()]+=(names!="" ? (',' + names) : names);
						$scope.ifmIsSensitivity[$("#hidValue").val()]+=(sensitive!="" ? (',' + sensitive) : sensitive);
					}else{
						$scope.ifmIds[$("#hidValue").val()]+=nn,
						$scope.ifmNames[$("#hidValue").val()]+=names;
						$scope.ifmIsSensitivity[$("#hidValue").val()]+=sensitive;
					}
				}
			}
		} else {
			$("#CustomsAreaList .infoLlist .ui_checkbox, .allSel").removeClass("checked").attr("checkedbtn", "false");
			for(var i=0;i<len;i++){
				var nn = "",names = "",sensitive="";
				nn = $("#CustomsAreaList .infoLlist .ui_checkbox").eq(i).attr('ifm_id'),
				names = $("#CustomsAreaList .infoLlist .ui_checkbox").eq(i).attr('ifm_name');
				sensitive = $("#CustomsAreaList .infoLlist .ui_checkbox").eq(i).attr('ifm_sensitivity');
				var qc=getSs(nn);
				if(qc||qc==0){						
					var ifmIdsArr=$scope.ifmIds[$("#hidValue").val()].split(','), 
					ifmNamesArr=$scope.ifmNames[$("#hidValue").val()].split(','),
					ifmIsSensitivityArr=$scope.ifmIsSensitivity[$("#hidValue").val()].split(',');
					ifmIdsArr.splice(qc,1), 
					ifmNamesArr.splice(qc,1), 
					ifmIsSensitivityArr.splice(qc,1);
					$scope.ifmIds[$("#hidValue").val()]=ifmIdsArr.join(','), 
					$scope.ifmNames[$("#hidValue").val()]=ifmNamesArr.join(','),
					$scope.ifmIsSensitivity[$("#hidValue").val()]=ifmIsSensitivityArr.join(',');
				}
			}
		}
	});

	$("#CustomsAreaList .infoLlist .ui_checkbox").live("click", function() {
		checkTrueFalse();
	});

	function checkTrueFalse() {
		var isTrue = "true";
		$("#CustomsAreaList .infoLlist .ui_checkbox").each(function() {
			var checkedbtn = $(this).attr("checkedbtn");
			if(checkedbtn == "false") {
				isTrue = "false";
				return;
			}
		});
		if(isTrue == "false") {
			$(".selectAllAreaGoGo .allSel").removeClass("checked").attr("checkedbtn", "false");
		} else {
			$(".selectAllAreaGoGo .allSel").addClass("checked").attr("checkedbtn", "true");
		}
	}

	//点击查询
	$("#checkQueryBtn").live("click", function() {
		curPage = 1;
		qDataFun(curPage);
	});
	$('.enterKeyDownElement').keydown(function(e) {
		if(e.keyCode == 13) {
			curPage = 1;
			qDataFun(1);
		}
	});
	//点击触发换页的按钮
	$("#pageArea .pNumBtn a").live("click", function() {
		curPage = parseInt($(this).attr("toPage"));
		qDataFun(curPage);
	});

	//点击触发分批显示的按钮
	$("#pageArea .columnsPage a").live("click", function() {
		numList = parseInt($(this).text());
		curPage = 1;
		qDataFun(curPage);
		subPage = $(this).index();
	});
	//跳转
	$("#pageArea .gopg .btn").live("click", function() {
		curPage = parseInt($("#pageArea .gopg .txt").val());
		//判断输入的页数是否大于最大的页数
		if(curPage>countPage){
			curPage=countPage;
		}
		if(curPage>0){
			qDataFun(curPage);
		}
	});

	function qDataFun(curPages) {
		ifmName = $("#ifmName").val();
		ifmNote = $("#ifmNote").val();
		selectJsonData = null;
		selectJsonData = {
			ifmName: ifmName,
			ifmNote: ifmNote
		};
//			console.log($tmpButton.attr("class"));
		var rscArr2 =  $tmpButton.attr("ifm_id").split(",");
//			console.log(rscArr2);
		$scope.edit.qTagList( $tmpButton, rscArr2, selectJsonData, curPages, numList, 1);
	};
	
	/*
	 * 分页
	 * */
	var numList =10; //每页列数
	var curPage = 1; //默认第一页
	var subPage=0;  //批量显示添加默认落点
	var totalPage=9; //最多显示分页数
	var selectJsonData = "";
	var countPage = 0;//页数总计
	function jsCk(t){
		if(!/^[1-9][0-9]*$/g.test(t.value)){
			t.value="";
			return false;
		}
	}
	var paging = {
		//加载分页
		"loadPage":function(data){
			var pCount = data.totalPages;//页数
			countPage = pCount;
			var pNums =  data.totalRecords;//总计条数
			var s1 = (totalPage-1)/2;
			var start_page = curPage - s1;
			var end_page = curPage + s1;
			if(start_page<=0){
				end_page = end_page - start_page + 1;
				start_page = 1;
			}
			if(end_page>pCount){
				end_page = pCount;
			}	  		
			var prevHtml ='<a toPage="'+(curPage-1)+'" href="javascript:void(0);"   class="str">&lt;</a>';
			var nextHtml ='<a toPage="'+(curPage+1)+'" href="javascript:void(0);"  class="end" >&gt;</a>';
			if(curPage<2)prevHtml="";
			if(curPage>=pCount)nextHtml="";
			var ppHtml = "";
			for(i=start_page;i<=end_page;i++){
			   var cur = "";
			   if(curPage==i)cur='class="cur"';
			   ppHtml = ppHtml+'<a toPage="'+i+'" href="javascript:void(0);"  '+cur+'>'+i+'</a>';
			}
			var pageHtml = '<span class="ic fl pr20 pCount">共<b>'+pNums+'</b>条记录</span><span class="sw fl pr20 columnsPage">显示 <a href="javascipr:void(0);" class="cur">10</a><a href="javascipr:void(0);" class="cur">50</a><a href="javascipr:void(0);" class="cur">全部</a></span><span class="gopg fr"><span class="fl">跳转到</span><input type="button" class="btn" value="go"><input type="text" min="1" class="txt" onkeyup="jsCk(this)"></span><div class="pg fr pNumBtn">'+prevHtml+ppHtml+nextHtml+'</div>';
			var pageArea = $('#pageArea');
			pageArea.html(pageHtml);
			
			//每页显示指定的数量
			var dd = pNums/10;
			var ddHtmls = "";
			var pCur = 0;
			if(pNums>0){
				pCur=0;
				pageArea.show();
			}else if(pNums==0){
				pCur=4;
				pageArea.hide();
			}
			$("#pageArea .columnsPage").html("显示 <a href='javascript:void(0);'>10</a><a href='javascript:void(0);'>20</a><a href='javascript:void(0);'>50</a><a href='javascript:void(0);'>全部</a>");
			$("#pageArea .columnsPage a").removeClass("cur").eq(subPage).addClass("cur");
			var s = 4; 
			for(var i=0;i<pCur;i++){
				$("#pageArea .columnsPage a").eq(s).remove();
				s -=1;
			}
		}
	}	
	
	$scope.domAjax = function(e) {
		var	list=[], moudleIds=[], ifmIdsArrs=[], ifmSensitiveArrs=[], paramsObj={};
		if (e === 'save') {
			if(modelId!=null){
				var rptModel = {
					"id":parseInt(modelId),
		            "name": null,
		            "groupId": null,
		            "isOpen": null,
		            "cycleId": null,
		            "note": null,
		            "moduleSort": null
				}
				var len = $(".mtable .moudleClass").length;
				for(var i=0;i<len;i++){
					ifmIdsArrs[i] = $scope.ifmIds[i].split(','),
					ifmSensitiveArrs[i] = $scope.ifmIsSensitivity[i].split(',');
					var ifmIdsArrsLen = ifmIdsArrs[i].length;
					
					for(var j=0;j<ifmIdsArrsLen;j++){
						if(ifmIdsArrs[i][j]){
							list.push({
								"moduleId":content[i].moduleId,
								"planId":ifmIdsArrs[i][j],
								"isSensitive":ifmSensitiveArrs[i][j],
								"modelId":null,
								"viewInfoId":null,
								"dimensionId":null
							});
						}else{
							layer.msg('“'+content[i].moduleName +'”的统计方案不能为空！',2,5);
							return false;
						}
					}
				}			
			}else{
				var rptModel = {
					"id":content.id,
		            "name": content.name,
		            "groupId": groupId,
		            "isOpen": content.isOpen,
		            "cycleId": content.cycleId,
		            "note": "",
		            "moduleSort": content.moduleSort
				}
				var len = $(".mtable .moudleClass").length;
				for(var i=0;i<len;i++){
					var ifmIdsV = $scope.ifmIds[i]||"";
					var ifmIsSensitivityV = $scope.ifmIsSensitivity[i]||"";
					moudleIds[i] = content.modulelist[i].id;
					ifmIdsArrs[i] = ifmIdsV.split(','),
					ifmSensitiveArrs[i] = ifmIsSensitivityV.split(',');
					var ifmIdsArrsLen = ifmIdsArrs[i].length;
					
					for(var j=0;j<ifmIdsArrsLen;j++){
						if(ifmIdsArrs[i][j]){
							list.push({
								"moduleId":content.modulelist[i].id,
								"planId":ifmIdsArrs[i][j],
								"isSensitive":ifmSensitiveArrs[i][j],
								"modelId":null,
								"viewInfoId":null,
								"dimensionId":null
							});
						}else{
							layer.msg('“' + content.modulelist[i].name + '”的统计方案不能为空！',2,5);
							return false;
						}
					}
				}			
			}
			paramsObj = {
				"rptModel":rptModel,
				"list":list
			}
			paramsObj = JSON.stringify(paramsObj);
//			console.log(paramsObj);debugger;
			if(modelId!=null){
				var url = basePath + 'rpt/view/update.do?id='+rptCycleId;
			}else{
				var url = basePath + 'rpt/view/insert.do';
			}
			$http.post(url,paramsObj).success(function(data) {
				var j = timeout_json(data, $window);
				if (j == false) {
					return false;
				}
				if(data.returnCode==10000){
					layer.msg(data.returnMessage, 1, 10);
					var t = setTimeout(function(){
						if(modelId!=null){
							//保存iframe窗口后，不跳转页面
							window.parent.$(".dtab").find('#jsgo a.cur').trigger('click');
							window.parent.layer.closeAll();
						}else{
							window.parent.location.href=basePath + 'report/reportTemplateList.jsp?parId=301';
							window.parent.layer.closeAll();
						}
					},1000);
				}else{ 
					layer.msg(data.returnMessage, 1, -1);
					return false;
				}
			});
		}else if(e === 'cancel'){
			window.parent.layer.closeAll();
		}
	};
});

